# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : message_manager.py
# Time       ：2023/8/1 10:28
# Author     ：YangYong
# version    ：python 3.10
# Description：orderlines运行消息的发布和订阅管理
"""
from abc import ABC, abstractmethod

from conf.config import QueueConfig
from public.utils.redis_utils import RedisUtils


class BaseMessageManager(ABC):

    @abstractmethod
    def publish(self, message: dict):
        pass

    @abstractmethod
    def subscribe(self):
        pass


class DebugMessageManager(BaseMessageManager):

    def __init__(self):
        self.queue_name = QueueConfig.debug_queue
        self.redis_client = RedisUtils(self.queue_name)

    def publish(self, message: dict):
        """发布debug消息"""
        self.redis_client.lpush(message)

    def subscribe(self):
        return self.redis_client.rpop()


class NoticeMessageManager(BaseMessageManager):
    def __init__(self):
        self.queue_name = QueueConfig.notice_queue
        self.redis_client = RedisUtils(self.queue_name)

    def publish(self, message: dict):
        self.redis_client.lpush(message)

    def subscribe(self):
        return self.redis_client.rpop()


class RunningLoggerMessageManager(BaseMessageManager):
    def __init__(self):
        self.queue_name = QueueConfig.running_logger_queue
        self.redis_client = RedisUtils(self.queue_name)

    def publish(self, message: dict):
        self.redis_client.lpush(message)

    def subscribe(self):
        return self.redis_client.rpop()
